import Vue from 'vue'
import vuex from 'vuex'
Vue.use(vuex)

// 获取cookic中的i参数
let i = window.sessionStorage.getItem('i')
// // 不存在时默认为1
if(i == '' || !i || isNaN(i)) {
  i = 1
}

let host = process.env.VUE_APP_BASE_URL // 配置了生产环境和开发环境，此处会根据环境不同而请求不同的地址，在环境配置中设置请求地址
let jssdk = host + '/app/index.php?c=entry&do=auth&m=social&r=sdk&i=' + i // jssdk请求地址
let base = host + '/app/index.php?c=entry&m=social&i=' + i // 基础微信请求数据地址
const state = {
  // 后台跳转微信地址路径
  towxUrl: 'https://rs.cdlw.site/app/index.php?c=entry&do=index&m=social&i='  + i + '&topath=',
  // 请求资源地址
  basicApiUrl: base,
  jssdkApiUrl: jssdk,

  // 微信分享内容
  shareTitle: '',
  shareLink: '',
  shareDesc: '',
  sharePic: '',

  // 图片引用公共地址
  globalPic: host + '/attachment/'
}

const mutations = {
  // 改变分享内容的方法
  shareTitleCg(state, msg) {
    state.shareTitle = msg
  },

  shareLinkCg(state, msg) {
    state.shareLink = msg
  },

  shareDescCg(state, msg) {
    state.shareDesc = msg
  },

  sharePicCg(state, msg) {
    state.sharePic = msg
  }
}

const store = new vuex.Store({
  state,
  mutations
})

export default store